package com.example.programming.sys.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.programming.sys.entity.HomeworkVo;
import com.example.programming.sys.entity.UserHomework;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * <p>
 *  Mapper 接口 chrimer
 * </p>
 *
 * @author chrimer
 * @since 2020-08-22
 */
public interface UserHomeworkMapper extends BaseMapper<UserHomework> {
    @Select(
    {"<script>",
            "select a.id as id,c.course as course,c.name as chapter,a.score as score,a.url as homeworkUrl,b.nickname as nickname,b.school as school,a.suggestion as suggestion  \n" +
                    "from user_homework a " ,
                    "LEFT JOIN user b on a.user_id = b.id " ,
                    "LEFT JOIN homework c on a.homework_id = c.id " ,
                    "where c.teacher = #{id}",
            "<when test='chapter!=null'>",
            "AND c.name like CONCAT('%',#{chapter},'%')",
            "</when>",
            "<when test='nickname!=null'>",
            "AND b.nickname like CONCAT('%',#{nickname},'%')",
            "</when>",
            "</script>"})
    IPage<HomeworkVo> page(@Param("id") String id, @Param("chapter")String chapter, @Param("nickname")String nickname,@Param("page") Page page);
}
